package com.dsteiner.xelavos.client.constants;

import static com.dsteiner.xelavos.client.controller.IHistoryToken.HT_OBJECT_ID;
import static com.dsteiner.xelavos.client.controller.IHistoryToken.HT_SELECTED_TAB;

import java.util.ArrayList;
import java.util.List;

import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.domain.Distinct;
import com.dsteiner.widgets.client.domain.ModelObject;
import com.dsteiner.xelavos.client.controller.PlaceController;
import com.dsteiner.xelavos.client.domain.Job;
import com.dsteiner.xelavos.client.domain.Leisure;
import com.dsteiner.xelavos.client.domain.Product;
import com.dsteiner.xelavos.client.domain.Service;
import com.dsteiner.xelavos.client.domain.User;
import com.dsteiner.xelavos.client.model.MainTabModel;


public interface Constants {

	public static class Util{

		private static final Distinct[] distinctableDashletList = new Distinct[]{
			new Distinct(Product.class.getName(), "name"),
			new Distinct(Service.class.getName(), "type"),
			new Distinct(Job.class.getName(), "name"),
			new Distinct(Leisure.class.getName(), "name")
		};
		
		private static final String XELAVOS_IMAGE_URL_PREFIX = "/xelavos/image?id=";

		public static Integer calculateRating(int ratingTotal, int ratingCount) {
			double rating = (double)ratingTotal / (double)ratingCount;
			if (rating % 1 < 0.5)
				rating -= rating%1;
			else
				rating += 1-rating%1;
			return (int)rating;
		}

		public static String getFileUploadUrl(ModelObject modelObject) {
			String url = "/xelavos/fileUpload?";
			if(modelObject != null){
				url += "type="+modelObject.getClass().getName();
				url += "&id="+modelObject.getId();
			}
			
			return url;
		}
		
		public static int getHeaderHeight(User user){
			return user != null ? HEIGHT_HEADER_SMALL : HEIGHT_HEADER_LARGE;
		}

		public static String getImageId(String imageUrl) {
			if(imageUrl == null)
				return null;
			return isXelavosImage(imageUrl) ? imageUrl : JsUtil.getInstance().gup(imageUrl, "id");
		}

		public static String getImageUrl(String imageId){
			if(imageId == null)
				return null;
			return imageId.contains("images.google.com") ? imageId : XELAVOS_IMAGE_URL_PREFIX+imageId;
		}
		
		public static String getMsgEmailNotExistant(String email) {
			return "email '"+email+"' no existe";
		}

		public static String getUserGAVar(User user) {
			return user != null ? "user" : "guest";
		}

		public static boolean isXelavosImage(String imageId) {
			return imageId != null && imageId.contains("images.google.com");
		}

		public static Distinct[] getDistinctableDashletList() {
			return distinctableDashletList;
		}

		public static String getModelObjectUrl(ModelObject modelObject) {
			return "http://www.xelavos.com#"+PlaceController.getHistoryToken(
					HT_SELECTED_TAB.setValue(MainTabModel.getTab(modelObject).getId()),
					HT_OBJECT_ID.setValue(modelObject.getId()));
		}

	}
	String ACT_CHANGED_ITEMS_PER_PAGE_LIST_BOX = "Changed ItemsPerPage ListBox";
	String ACT_CHANGED_SORT = "Changed Sort";
	String ACT_CLICKED_ADD_BUTTON = "Clicked Add Button";
	String ACT_CLICKED_CREATE_BUTTON = "Clicked Create Button";
	String ACT_CLICKED_CREATE_LINK = "Clicked Create Link";
	String ACT_CLICKED_ICON = "Clicked Icon";
	String ACT_CLICKED_LINK = "Clicked Link";
	String ACT_CLICKED_LOGIN_BUTTON = "Clicked Login Button";
	String ACT_CLICKED_MY_ENTRIES_LINK = "Clicked My Entries Link";
	String ACT_CLICKED_MY_PROFILE_LINK = "Clicked My Profile Link";
	String ACT_CLICKED_PAGE_LINK = "Clicked Page Link";
	String ACT_CLICKED_SEARCH_BUTTON = "Clicked Search Button";
	
	String ACT_CLICKED_USER_LINK = "Clicked User Link";
	String ACT_MSG_SHOWN = "Msg Shown";
	String ACT_RATE_DOWN = "Rate Down";
	String ACT_RATE_UP = "Rate Up";
	String ACT_TYPED_ENTER_IN_SEARCH_BOX = "Typed Enter In Search Box";
	
	String CAT_ACCOUNT = "Account";
	String CAT_COMMENT = "Commenting";
	String CAT_DISPLAY = "Displaying";
	String CAT_PAGINATION = "Pagination";
	
	String CAT_PUBLISHING = "Publishing";
	String CAT_RATING = "Rating";
	
	String CAT_SEARCH = "Searching";
	String CAT_TAB = "Tabing";
	String COOKIE_NAME_USER_ID = "user_id";
	String DATE_FORMAT = "dd/MM/yyyy";
	String DATE_FORMAT_SHORT = "dd/MM/yy";
	int HEIGHT_HEADER_LARGE = 90;
	int HEIGHT_HEADER_SMALL = 30;
	int HEIGHT_TAB = 60;
	String ID_CONTACT = "contact";
	String ID_CONTENT = "content";
	String ID_CONTENT_MAIN = "contentmain";
	String ID_CONTENT_TAB = "contenttab";
	String ID_CONTENT_USERS = "contentusers";
	String ID_CREATE_ACCOUNT = "createaccount";
	String ID_HEADER = "header";
	String ID_LOGIN = "login";
	String ID_LOGO = "logo";
	String ID_LOGO_SMALL = "logo_small";
	String ID_USER_INFO = "userinfo";
	String ID_USER_STATS = "userstats";
	
	String LBL_NO_COMMENT_ENTERED = "No Comment Entered";
	String LBL_NOT_LOGGED_IN = "Not Logged In";
	int MAX_COUNT_STRING = 500;
	int MAX_FILE_SIZE = 1000000;
	String MSG_CONFIRMATION_EMAIL_SENT = "gracias por registrarse - en unos momentos va a recibir <br>" +
			"un correo para confirmar su direccion electronica";
	String MSG_EMAIL_ALREADY_REGISTERED = "email ya esta registrada - use otra\n";
	String MSG_FILE_UPLOAD_FAILED = "Error: subir el archivo fallo";
	String MSG_FILE_UPLOAD_TOO_LARGE = "Error: archivo demasiado grande";
	String MSG_INSERT_FULL_EMAIL = "ingrese su email completa - ej carlos.lopez@gmail.com";
	String MSG_MESSAGE_SENT = "mensaje enviado exitosamente";
	
	String MSG_NICKNAME_ALREADY_REGISTERED = "sobrenombre ya esta registrado - ingrese otro\n";
	String MSG_NO_RESULTS = "no se encontro <strong>ningun resultado</strong>";
	String MSG_OBJ_ALREADY_RATED = "ya lo ha clasificado";
	String MSG_OBJ_ALREADY_TRACKED = "ya esta siguiendo este registro";
	String MSG_PASSWORD_NOT_CORRECT = "contraseña no es correcta";
	String MSG_VALIDATE_ACCOUNT = "confirma su direccion electronica";
	String NUMBER_FORMAT_QUETZAL = "Q #,###.##";
	int POLL_DATA_MS = 120000;
	int WIDTH_USERS_PANEL = 300;

}
